﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Xml.Serialization;

using Otonomos.Utils;

namespace Otonomos.World
{
    public class Point2D : Object2D
    {
        public double X { get; private set; }
        public double Y { get; private set; }

        public static Point2D Origin = new Point2D();

        public Point2D() : this(0.0, 0.0)
        {
        }

        public Point2D(double x, double y)
        {
            X = x;
            Y = y;
        }

        public override double Distance(Point2D other)
        {
            return Math.Sqrt((this.X - other.X) * (this.X - other.X) +
                (this.Y - other.Y) * (this.Y - other.Y));
        }

        public override bool Equals(object obj)
        {
            return this.Equals(obj as Point2D);
        }

        public override string ToString()
        {
            return string.Format("({0}/{1})", X, Y);
        }

        public bool Equals(Point2D other)
        {
            if (other == null)
                return false;
            return other.X == X && other.Y == Y;
        }
        
        public int CompareTo(Point2D other)
        {
            if (other.X != X)
            {
                return X.CompareTo(other.X);
            }
            return Y.CompareTo(other.Y);
        }

        public static bool operator ==(Point2D a, Point2D b)
        {
            return EqualsUtility.OperatorEquals(a, b);
        }

        public static bool operator !=(Point2D a, Point2D b)
        {
            return !EqualsUtility.OperatorEquals(a, b);
        }

        public override int GetHashCode()
        {
            return X.GetHashCode() ^ Y.GetHashCode();
        }
    }
}
